package com.yunji.hushuang.plugin.demo.interceptor;

import com.alibaba.fastjson.JSON;
import com.yunji.hushuang.plugin.Interceptor;
import com.yunji.hushuang.plugin.Intercepts;
import com.yunji.hushuang.plugin.Invocation;
import com.yunji.hushuang.plugin.Signature;
import com.yunji.hushuang.plugin.demo.source.DemoParam;
import com.yunji.hushuang.plugin.demo.source.IExecutor;

/**
 * 日志拦截器，记录入参、出参
 *
 * @author hushuang
 * @since 2019/10/16
 */
@Intercepts(@Signature(type = IExecutor.class, method = "execute", args = DemoParam.class))
public class LogInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Exception {
        System.out.println("LogInterceptor 开始调用，入参为：" + JSON.toJSONString(invocation.getArgs()));
        Object result = invocation.proceed();
        System.out.println("LogInterceptor 结束调用，出参为：" + JSON.toJSONString(result));
        return result;
    }
}